﻿using System.Transactions;
using KingRoad.EPM.CompletionMaterialsEntity.Model;
using Unis.Framework.RuleBase.Common;
using System.Collections.Generic;
using System;

namespace KingRoad.EPM.CompletionMaterialsDAL.CommonFileService
{
    /// <summary> 
    /// 文件生成时间 2017/4/5 4:46:30
    /// </summary> 
    public class CommonFileService : BaseService<CommonFileInfo>, ICommonFileService
    {
        #region ICommonFileService 成员
        /// <summary>
        /// 批量插入附件
        /// </summary>
        /// <param name="bizId">业务ID（对应具体表AssisId）</param>
        /// <param name="bizType">业务编码</param>
        /// <param name="fileIds">文件IDS</param>
        /// <returns>返回插入CommonFile表后，返回的主键IDs</returns>
        public string BatchAddAttach(List<CommonFileInfo> commonFileList)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    var ids = "";
                    commonFileList.ForEach(t =>
                    {
                        ids += DatabaseExcuteByXmlHelper.NewInstance.ExecuteScalar("CommonFile", "AddObject", new object[] { t.FILE_TYPE, t.FILE_TYPEID, "", null, "", "", t.FILE_FILEID }) + ",";
                    });
                    if (!String.IsNullOrEmpty(ids))
                    {
                        ids = ids.Substring(0, ids.Length - 1);
                        scope.Complete();
                    }
                    return ids;

                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }

}

